package com.sxbbc.common.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxbbc.common.core.dto.jz.BAccountVO;
import com.sxbbc.common.core.dto.jz.DataTransactionVo;
import com.sxbbc.common.core.entity.jz.BAccount;
import com.sxbbc.common.core.enums.BusinessScopeEnums;
import com.sxbbc.common.core.mapper.jz.BAccountMapper;
import com.sxbbc.common.core.mapper.jz.OrderMainMapper;
import com.sxbbc.common.core.service.IBAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 店铺账户表 服务实现类
 * </p>
 *
 * @author xiaoky
 * @since 2019-06-04
 */
@Service
public class BAccountServiceImpl extends ServiceImpl<BAccountMapper, BAccount> implements IBAccountService {

    @Autowired
    private BAccountMapper bAccountMapper;
    @Autowired
    private OrderMainMapper orderMainMapper;

    @Override
    public BAccount selectByBid(Integer bid) {
        QueryWrapper<BAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("bid", bid);
        return super.getOne(wrapper);
    }

    @Override
    public boolean updateByBid(BAccount bAccount) {
        QueryWrapper<BAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("bid", bAccount.getBid());
        return super.update(bAccount, wrapper);
    }

    @Override
    public boolean removeByBid(Integer bid) {
        QueryWrapper<BAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("bid", bid);
        return super.remove(wrapper);
    }

    @Override
    public IPage<BAccountVO> queryPage(IPage<BAccountVO> page, BAccountVO vo) {
        super.baseMapper.queryPage(page, vo);
        page.getRecords().forEach(x -> x.setScopeName(BusinessScopeEnums.getName(x.getOnOff())));
        return page;
    }

    @Override
    public BigDecimal symAccount() {
        return bAccountMapper.sumTotalByType(1);
    }


    /**
     * 查询商家交易排行列表
     * @param vo
     * @return
     */
    @Override
    public List<DataTransactionVo> queryBusinessTransaction(DataTransactionVo vo) {
        return orderMainMapper.queryBusinessTransaction(vo);
    }

}
